var IndexModule = function () {
    var editable = function () {

        return {
            init: function () {
            	var handleValidation = function() {
                    var formAdd = $('#message');
                    var validator = formAdd.validate({
                        focusInvalid: true,
                        rules: {
                        	wechat: {
                                required: true
                            },
                        	name: {
                                required: true
                            },
                            mobile:{
                            	number:true,
                            	rangelength:[10,12],
                            },
                        },
                        messages:{
                            name:{
                                required:"名字要填哦",
                              },
	                        wechat: {
	                            required: '填了这个，这样我就可以找你玩耍啦~~',
	                        },
                            mobile:{
                            	number:"饭可以乱吃，电话不能乱填哦",
                            	rangelength:"饭可以乱吃，电话不能乱填哦",
                            },
                        },
                        success: function (label, element) {
//                            var icon = $(element).parent('div');
                            $(element).removeClass('has-error').addClass('has-success'); // set success class to the control group
//                            icon.removeClass("fa-warning").addClass("fa-check");
                        },

                        submitHandler: function (form) {
                            var json = $('form#message').serializeJSON();
                            $.ajax({
                             	"contentType":"application/json; charset=UTF-8",
                                 "dataType" : 'json',
                                 "type" : "POST",
                                 "url" : ctx+'/message/doAdd',
                                 "data" : json,
                                 "success" : function(msg){
                                	 if(msg.code == 0){
                                		 bootbox.alert("服务器偷了个小懒,呜呜~");
                                	 }else{
                                		 bootbox.alert("小生在此感谢了");
                                	 }
                                 }
                             });
                        }
                    });
            }
            	handleValidation();
                //添加留言
//                $('#submit').click(function(){
//                	var form = $("form#message").serializeJSON();
//                	  
//                });
            }

        };

    }();
    
    return {
        init: function () {
        	editable.init();
        }
    };
}();